package com.cartgo.controller.test
{
	import com.cartgo.pmodel.test.TestRemotePModel;
	import com.cartgo.services.ICoreDelegates;
	import com.cartgo.services.ITestDelegates;
	
	import flash.events.ErrorEvent;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	import org.swizframework.utils.services.ServiceHelper;

	public class TestRemoteCtrl
	{
		[Bindable]
		[Inject]
		public var model:TestRemotePModel;
		
		[Inject]
		public var serviceHelper:ServiceHelper;
		
		[Inject]
		public var delegate:ITestDelegates;
		
		public function TestRemoteCtrl()
		{
			
		}
		
		public function test():void
		{
			serviceHelper.executeServiceCall(delegate.helloWorld(), onTestResult, onRemoteError);
		}
		
		public function onTestResult(evt:ResultEvent):void{
			//model.testString = evt.result.toString();
			model.testList = new ArrayCollection(evt.result as Array);
		}
		
		public function onRemoteError(evt:FaultEvent):void{
			mx.controls.Alert.show(evt.fault.faultString + "\n" + evt.fault.faultDetail);
		}
	}
}